package ercahshu

func findBottomLeftValue(root *TreeNode) int {
	// 前序遍历进行第一个左侧节点的搜索
	if root == nil {
		return 0
	}
	height := -1
	res := 0
	var dfs func(node *TreeNode, depth int)
	dfs = func(node *TreeNode, depth int) {
		if node == nil {
			return
		}
		if depth > height {
			depth = height
			res = node.Val
		}
		dfs(node.Left, depth+1)
		dfs(node.Right, depth+1)
	}
	dfs(root, 0)
	return res
}
